<?php 

class Model_MemberLike extends Model{

	function __construct(){

	}
	
	/* 判斷是否like
	* $mid 			int 會員id
	* $section		string	 	section名稱：product,report,comment,member
	* $sid			int			section 的id
	* return		array		資料數組
	*/
	function getMemberLike($mid,$section,$sid,$page=1,$size=3){
		
		$where = " status=1 ";
		if(intval($mid)) {
			$where .=" and mid=".intval($mid);
		}
		if($section) {
			$where .=" and section='".$section."'";
		}
		if(intval($sid)) {
			$where .=" and sid=".intval($sid);
		}	
		
		$param = array();
		$param['field'] = "";
		$param['where'] = $where;
		$param['order'] = "id desc"; //"id asc"
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $size;
		$param['page'] = $page;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('member_like',$param);
		return $data['result'];
	}
        
        function getMemberLikeNum($mid,$section,$sid){
		
		$where = "  status=1  ";
		if(intval($mid)) {
			$where .=" and mid=".intval($mid);
		}
		if($section) {
			$where .=" and section='".$section."'";
		}
		if(intval($sid)) {
			$where .=" and sid=".intval($sid);
		}	
		
		$param = array();
		$param['field'] = "";
		$param['where'] = $where;
		$param['order'] = "id desc"; //"id asc"
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  1;
		$param['page'] = 1;
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('member_like',$param);
		return $data['pageinfo'];
	}
	
	/* 判斷是否unlike
	* $mid 			int 會員id
	* $section		string	 	section名稱：product,report,comment,member
	* $sid			int			section 的id
	* return		array		資料數組
	*/
	function getMemberUnlike($mid,$section,$sid){
		
		if(intval($mid)) {
			$where ="mid=".intval($mid);
		}else{
			 return false;
		}
		if($section) {
			$where .=" and section='".$section."'";
		}else{
			 return false;
		}
		if(intval($sid)) {
			$where .=" and sid=".intval($sid);
		}else{
			 return false;
		}		
		
		$param = array();
		$param['field'] = "";
		$param['where'] = $where;
		$param['order'] = $orderby; //"id asc"
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  "";
		$param['page'] = "";
		$param['join'] = "";
		$param['on'] = "";
		$data = db_query_hash('member_unlike',$param);
		return $data['result'];
	}
	
	/* 獲得關注會員列表
	* $mid 			int 會員id
	* $sid 			int 被關注的會員id
	* return		array		資料數組
	*/
	function getAllLikeMember($mid=0,$sid=0,$page = 1, $size = 3){
		
		$where="  TB1.status=1  ";
		$where .=" and TB1.section='member'";
		if(intval($mid)) $where .=" and TB1.mid=".intval($mid);
		if(intval($sid)) $where .=" and TB1.sid=".intval($sid);
		
		$param = array();
		$param['field'] = "TB1.*,TB2.photo,TB2.username,TB2.member_type";
		$param['where'] = $where;
		$param['order'] = ""; //"id asc"
		$param['group'] = "";
		$param['limit'] = "";
		$param['pagesize'] =  $size;
		$param['page'] = $page;
		$param['join'] = "LEFT JOIN member_imore";
		$param['on'] = "TB1.sid = TB2.id";
		$data = db_query_hash('member_like',$param);
		return $data['result'];
	}
}
?>
